/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H
#define OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H

#include <cstdint>
#include <string>
#include <memory>
#include "single_instance.h"
#include "message_req.h"
#include "message_rsp.h"

namespace OHOS {
namespace DistributedHardware {
static int32_t GetTrustedDeviceList(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t GetLocalDeviceInfo(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t GetUdidByNetworkId(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t GetUuidByNetworkId(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t StartDeviceDiscovery(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t StopDeviceDiscovery(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t SetUserOperation(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t GetFaParam(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t AuthenticateDevice(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t UnAuthenticateDevice(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
static int32_t VerifyAuthentication(std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);

typedef struct {
    int32_t cmdCode;
    int32_t (*MsgProcess) (std::shared_ptr<MessageReq> req, std::shared_ptr<MessageRsp> rsp);
} CmdMap;

static const CmdMap g_cmdMap[] = {
    {GET_TRUST_DEVICE_LIST, GetTrustedDeviceList},
    {GET_LOCAL_DEVICE_INFO, GetLocalDeviceInfo},
    {GET_UDID_BY_NETWORK, GetUdidByNetworkId},
    {GET_UUID_BY_NETWORK, GetUuidByNetworkId},
    {START_DEVICE_DISCOVER, StartDeviceDiscovery},
    {STOP_DEVICE_DISCOVER, StopDeviceDiscovery},
    {SERVER_USER_AUTH_OPERATION, SetUserOperation},
    {SERVER_GET_DMFA_INFO, GetFaParam},
    {AUTHENTICATE_DEVICE, AuthenticateDevice},
    {UNAUTHENTICATE_DEVICE, UnAuthenticateDevice},
    {VERIFY_AUTHENTICATION, VerifyAuthentication},
};

class CommandDispatch {
DECLARE_SINGLE_INSTANCE(CommandDispatch);
public:
     int32_t MessageSendCmd(int32_t cmdCode, std::shared_ptr<MessageReq> req,
                            std::shared_ptr<MessageRsp> rsp);
};
}
}
#endif